//
//  MYGCaseFilesViewController.swift
//  MYGrow
//
//  Created by 王振明 on 2024/3/16.
//

import UIKit

class MYGCaseFilesViewController: MYGBaseController {

    var data:MYGCaseSubModel = MYGCaseSubModel()
    private var contents:[[String:String]] = []
    private var model = MYGCaseListFileModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        self.title = "病历夹"
        
        let arr:[[String:String]] = [["name":"门诊","type":"1"],
                         ["name":"检验检查","type":"2"],
                         ["name":"用药记录","type":"3"]
                         ,["name":"手术","type":"4"],
                         ["name":"体检","type":"5"]
                        ]//
        self.contents = arr
        
        configUI()
        getList()
        
    }
    private func configUI(){
        view.addSubview(casesTable)
        casesTable.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(statusBarHeight + 44)
        }
    }
    private lazy var casesTable: UITableView = {
        let cont = UITableView(frame: CGRectZero, style: .grouped)
        cont.delegate = self
        cont.dataSource = self
        cont.separatorStyle = .none
        cont.backgroundColor = .clear
        cont.showsVerticalScrollIndicator = false
        cont.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0.01))
        return cont
    }()
}
extension MYGCaseFilesViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return contents.count
    }
//    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//        return 0.01
//    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return SCALEWIDTH(98.5)
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = MYGCaseFilesTableViewCell(style: .default, reuseIdentifier: "MYGCaseFilesTableViewCell")
        cell.selectionStyle = .none
        cell.data = self.contents[indexPath.row]
        return cell
    }
//    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        let vc = MYGAddCaseFilesViewController()
//        vc.model = self.model
//        vc.index = indexPath.row
//        vc.data = self.data
//        UIViewController.currentViewController?.navigationController?.pushViewController(vc)
//    }
    
}

extension MYGCaseFilesViewController {
     
    func getList(){
        MYGLoading.show()
        
        MMYGNetwork<MYGCaseFilesApi,MYGCaseListFileModel>.request(target: .getClassClampInfo(id: model.id)) { item in
            MYGLoading.hide()
            guard let model = item else {
                return
            }
            self.model = model
            
        } failed: { _, error in
            MYGLoading.hide()
            MMYGHUD.showToast(text: error)
        }
    }
    
}
